package org.un.cava.birdeye.ravis.components.renderers.edgeLabels{
	import flash.events.Event;
	import flash.events.TimerEvent;
	import flash.geom.Point;
	import flash.utils.Timer;
	
	import mx.core.IDataRenderer;
	import mx.core.UIComponent;
	
	import org.un.cava.birdeye.ravis.graphLayout.visual.IVisualEdge;
	

	
public class TimerShiningLineLabelRenderer extends UIComponent implements IDataRenderer{
	private var _data:Object = new Object();
	private var _fromPoint:Point = new Point(0,0);
	private var _toPoint:Point = new Point(0,0);
	private var _transferFrequency:uint=1;	
	private var timer:Timer;
	private var transparency:Boolean=false;

	
	
	public function TimerShiningLineLabelRenderer(){
		super();	
		timer=new Timer(10000,0);
		timer.start();
	}
	
	public function get data():Object{
		return _data;
	}
	public function set data(o:Object):void{
		_data=o;
		this.invalidateProperties();
		this.invalidateDisplayList();
	}
	public function get fromPoint():Point{
			return _fromPoint;
		}
	public function set fromPoint(p:Point):void{
			if(p==null||p==this._fromPoint)
				return;
			else{
				this._fromPoint=p;
				this.invalidateProperties();
				this.invalidateDisplayList();
			}
				
			
		}
	public function setFromPoint(p:Point):void{
			if(p==null||p==this._fromPoint)
				return;
			else{
				this._fromPoint=p;
				this.invalidateProperties();
				this.invalidateDisplayList();
			}
				
			
		}
		
	public function get toPoint():Point{
			return _toPoint;
		}
		
	public function set toPoint(p:Point):void{
		if(p==null||p==this._toPoint)
			return;
		else{
			this._toPoint=p;
			this.invalidateProperties();
			this.invalidateDisplayList();
		}
				
			
	}
	public function setToPoint(p:Point):void{
		if(p==null||p==this._toPoint)
			return;
		else{
			this._toPoint=p;
			this.invalidateProperties();
			this.invalidateDisplayList();
		}		
	}
	public function get transferFrequency():uint{
		return _transferFrequency;
	}
	public function set transferFrequency(tf:uint):void{
		if(tf==this._transferFrequency){
			return;
		}else{
			this._transferFrequency=tf;
			(this.data as IVisualEdge).data.@frequency=tf.toString();
			this.invalidateProperties();
			this.invalidateDisplayList();

		}
	}
	
	override protected function updateDisplayList(unscaledWidth:Number,unscaledHeight:Number):void {
            super.updateDisplayList(unscaledWidth, unscaledHeight);
            this.graphics.clear();
            if(this.data==null){
            	this.visible=false;
				return;
			}
			var isTran:String=(this.data as IVisualEdge).data.@transferring;
			if(isTran=="false"){
				this.visible=false;
				return;
			}
			_fromPoint=(this.data as IVisualEdge).edge.node1.vnode.viewCenter;
			_toPoint=(this.data as IVisualEdge).edge.node2.vnode.viewCenter;
			var frequency:String=(this.data as IVisualEdge).data.@frequency;
			this._transferFrequency=uint(frequency);
			
			trace("fromPonit: "+this._fromPoint.x+","+this._fromPoint.y+"; toPoint: "+this._toPoint.x+","+this._toPoint.y);
 			this.graphics.lineStyle(2,0xff0101,1);
			this.graphics.moveTo(_fromPoint.x, _fromPoint.y);			
			this.graphics.lineTo(_toPoint.x,_toPoint.y);
			//trace("ShiningLineLabelRender updateDisplaylist");
			beginShining(); 
			//trace(this.toString()+"'s updateDisplayList()");           
            }

	public function beginShining():void{
		timer.addEventListener(TimerEvent.TIMER,shining);
	}
	private function shining(eventObj:TimerEvent):void{
			if(transparency)
			 	this.alpha=0;
			else
				this.alpha=1;
			this.transparency=!this.transparency;		
	}
	public function refresh(eventObj:Event):void{
		//trace("ShiningLineLabelRender catch event "+eventObj.type);
		this.invalidateProperties();
		this.invalidateDisplayList();
	}
}
}